<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>角色分配</title>
<link rel="stylesheet" href="${ctx }/resources/zTree/css/metroStyle/metroStyle.css" type="text/css">
<link rel="stylesheet" href="${ctx }/resources/layui/css/layui.css" media="all" />
<script type="text/javascript" src="${ctx }/resources/zTree/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/zTree/js/jquery.ztree.core.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/zTree/js/jquery.ztree.excheck.min.js"></script>
</head>
<body class="childrenBody">
	
	<ul id="treePermission" class="ztree"></ul>
	
	<div style="text-align: center;">
		<!--lay-submit标记当按钮是一个提交按钮   -->
		<!-- <button type="button" class="layui-btn" id="saveRolePermission">确认</button> -->
		<a href="javascript:void(0)" class="layui-btn" onclick="saveRolePermission()">确认</a>
	</div>
	<script type="text/javascript" src="${ctx }/resources/layui/layui.js"></script>
</body>
<script type="text/javascript">
var setting = {
	data: {
		simpleData: {
			enable: true
		}
	},
	check: {
		enable: true   //显示 / 不显示 复选框或单选框
	}
};	
$(document).ready(function(){
	initTree();
});
function initTree() {
	$.post("${ctx}/role/loadRolePermissionTree.action?id=${roleVo.id}",function(zNodes){
		$.fn.zTree.init($("#treePermission"), setting, zNodes);
	})
}
var layer;
layui.use('layer',function(){
	layer=layui.layer;
})

function saveRolePermission() {
	var treeObj = $.fn.zTree.getZTreeObj("treePermission");
	var nodes = treeObj.getCheckedNodes(true);
	var params="?id=${roleVo.id}";
	for (var i = 0; i < nodes.length; i++) {
		params+="&ids="+nodes[i].id
		//alert(params);
	}
	$.post("${ctx}/role/saveRolePermission.action"+params,function(obj){
		//alert(params);
		layer.msg(obj.msg);
		parent.tableIns.reload();//刷新表格
		//parent.parent.left.initTree();//刷新左边的树
		//关闭窗口
		var index=layer.getFrameIndex(window.name);
		parent.layer.close(index);
	})
}
</script>

</html>